package com.yzcs.tvapp

import android.app.Application
import android.content.Context
import com.fy.baselibrary.application.BaseActivityLifecycleCallbacks
import com.fy.baselibrary.application.ioc.ConfigUtils
import com.fy.baselibrary.statuslayout.OnStatusAdapter
import com.fy.baselibrary.utils.Constant
import com.fy.baselibrary.utils.CrashHandler
import com.fy.baselibrary.utils.ResUtils
import com.fy.baselibrary.utils.ScreenUtils


/**
 * description Application
 * Created by fangs on 2021/8/27 13:36.
 */
class MoviesApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        initConfig(this)
        initConfig()

        CrashHandler.getInstance().init(this)
    }

    private fun initConfig() {
        var designWidth = ResUtils.getMetaData(this, "rudeness_Adapter_Screen_width", 0)
        ScreenUtils.setCustomDensity(this, designWidth as Int)

//        设置activity 生命周期回调
        registerActivityLifecycleCallbacks(BaseActivityLifecycleCallbacks())
    }

    private fun initConfig(context: Context) {
        Constant.isOrientation = true;

        ConfigUtils.ConfigBiuder()
            .setBackImg(R.drawable.ic_nav_back)
            .setBgColor(R.color.appHeadBg)
            .setTitleColor(R.color.white)
            .setTitleCenter(true)
            .setFontDefault(false)
            .setBaseFile("movies", 0)
            .setEnableCacheInterceptor(true)
            .setDEBUG(BuildConfig.DEBUG)
            .setBASE_URL(BuildConfig.moviesURL)
            .setStatusAdapter(object : OnStatusAdapter{
                override fun errorViewId(): Int {
                    return R.layout.state_include_error
                }

                override fun retryViewId(): Int {
                    return R.id.tvTry
                }

                override fun netWorkErrorView(): Int {
                    return R.layout.state_include_networkerror
                }

                override fun emptyDataView(): Int {
                    return R.layout.state_include_emptydata
                }
            })
            .create(context)
    }

}